﻿@model  RentHouse.DTO.HouseEditDTO

@{
    ViewBag.Title = "添加房源";
}


<div class="pd-20">
    <form class="form form-horizontal" id="houseAddForm" autocomplete="off">
        <div class="row cl">
            <label class="form-label col-2"><span class="c-red">*</span>区域：</label>
            <div class="formControls col-2">
                <span class="select-box">
                    @Html.DropDownList("RegionId", ViewBag.RegionList as List<SelectListItem>, "==请选择==", new { @class = "select" })
                </span>
            </div>
            <label class="form-label col-2">小区：</label>
            <div class="formControls col-2">
                <select class="select" id="sel_CommunityId" name="CommunityId">
                    <option>==请选择==</option>
                </select>
            </div>
            <label class="form-label col-2">房型：</label>
            <div class="formControls col-2 skin-minimal">
                @Html.DropDownList("RoomTypeId", ViewBag.RoomTypeList as List<SelectListItem>, "==请选择==", new { @class = "select" })
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2">地址：</label>
            <div class="formControls col-6">

                <input type="text" class="input-text" placeholder="详细地址" name="Address" datatype="*" nullmsg="地址不能为空" value="@Html.DisplayFor(e=>e.Address)">
            </div>
            <label class="form-label col-2">月租金：</label>
            <div class="formControls col-2 skin-minimal">
                <input type="text" class="input-text" name="MonthRent" datatype="n" nullmsg="租金要三思呀" value="@Html.DisplayFor(e=>e.MonthRent)">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2"><span class="c-red">*</span>状态：</label>
            <div class="formControls col-2">
                <span class="select-box">
                    @Html.DropDownList("StatusId", ViewBag.StatusList as List<SelectListItem>, "==请选择==", new { @class = "select" })
                </span>
            </div>
            <label class="form-label col-2">面积：</label>
            <div class="formControls col-2">
                <input type="text" class="input-text" placeholder="平米" name="Area" datatype="n" nullmsg="面积要三思呀" value="@Html.DisplayFor(e=>e.Area)">
            </div>
            <label class="form-label col-2">装修：</label>
            <div class="formControls col-2 skin-minimal">
                @Html.DropDownList("DecorateStatusId", ViewBag.DecorateStatusList as List<SelectListItem>, "==请选择==", new { @class = "select" })
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2"><span class="c-red">*</span>楼层：</label>
            <div class="formControls col-1">
                <input type="text" class="input-text" placeholder="所在层" name="FloorIndex" datatype="n" nullmsg="几楼呢" value="@Html.DisplayFor(e=>e.FloorIndex)">

            </div>
            <div class="formControls col-1">
                <input type="text" class="input-text" placeholder="总层数" name="TotalFloorCount" datatype="n" nullmsg="几楼呢" value="@Html.DisplayFor(e=>e.TotalFloorCount)">

            </div>

            <label class="form-label col-2">类别：</label>
            <div class="formControls col-2 skin-minimal">
                @Html.DropDownList("TypeId", ViewBag.TypeList as List<SelectListItem>, "==请选择==", new { @class = "select" })
            </div>

            <label class="form-label col-2">朝向：</label>
            <div class="formControls col-2 skin-minimal">
                <input type="text" class="input-text" name="Direction" datatype="*" nullmsg="朝向是哪里" value="@Html.DisplayFor(e=>e.Direction)">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2">可看房时间：</label>
            <div class="formControls col-4">
                <input type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}'})" id="datemin" class="input-text Wdate" style="width:180px;" name="LookableDateTime" datatype="*" nullmsg="好好填写时间" value="@Html.DisplayFor(e=>e.LookableDateTime)">
            </div>
            <label class="form-label col-2">入住时间：</label>
            <div class="formControls col-4">
                <input type="text" name="CheckInDateTime" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'datemin\')}'})" id="datemax" class="input-text Wdate" style="width:180px;" datatype="*" nullmsg="好好填写时间" value="@Html.DisplayFor(e=>e.CheckInDateTime)">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2">业主姓名：</label>
            <div class="formControls col-4">
                <input type="text" class="input-text" name="OwnerName" datatype="*" nullmsg="业主叫什么" value="@Html.DisplayFor(e=>e.OwnerName)">
            </div>
            <label class="form-label col-2">业主电话：</label>
            <div class="formControls col-4">
                <input type="text" class="input-text" name="OwnerPhoneNum" datatype="m" nullmsg="电话不要胡写嘛" value="@Html.DisplayFor(e=>e.OwnerPhoneNum)">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2">房源描述：</label>
            <div class="formControls col-10">
                @*<textarea class="textarea" name="Description" datatype="*" nullmsg="房源描述也要写的"></textarea>*@

                <!-- 加载编辑器的容器 -->
                <script id="HouseDescription" name="Description" type="text/plain">
                    @System.Web.HttpUtility.HtmlDecode(Model.Description)
                    ue.setContent()
                </script>

            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-2">配置设置：</label>
            <div class="formControls col-10">
                @foreach (var item in Model.HouseAttachments)
                {
                    <input type="checkbox" id="AttachmentId_@item.AttachmentId" name="AttachmentIds" value="@item.AttachmentId" checked="@item.IsUsed" />
                    <label for="AttachmentId_@item.AttachmentId">@item.Name</label>

                }
            </div>
        </div>

        <div class="row cl">
            <div class="col-10 col-offset-2">
                <button class="btn btn-primary radius" type="button" id="btn_Save"><i class="Hui-iconfont">&#xe632;</i> 保存</button>

            </div>
        </div>
        @Html.HiddenFor(e => e.Id)
    </form>
</div>
@section footScript
{
    <script>

        $(function () {
            function htmlDecode(text) {
                         //1.首先动态创建一个容器标签元素，如DIV
                       var temp = document.createElement("div");
                        //2.然后将要转换的字符串设置为这个元素的innerHTML(ie，火狐，google都支持)
                         temp.innerHTML = text;
                         //3.最后返回这个元素的innerText(ie支持)或者textContent(火狐，google支持)，即得到经过HTML解码的字符串了。
                         var output = temp.innerText || temp.textContent;
                        temp = null;
                         return output;
            }
            //实例化编辑器
            var ue = UE.getEditor('HouseDescription');

            ue.addListener("ready", function () {
                // editor准备好之后才可以使用//
                var str = '@System.Web.HttpUtility.HtmlDecode(Model.Description)';
                str = htmlDecode(str);
                ue.setContent(str);
                //ue.setContent('<p>哈哈哈哈</p>');
            });

            //对用户输入的信息进行校验
            //初始化验证插件
            var validform = $("#houseAddForm").Validform({ tiptype: 2 });

            $("#btn_Save").click(function () {

                var formObj = $("#houseAddForm").serializeArray();

                //当验证通过的时候发送ajax请求
                if (validform.check(false)) {

                    $.post("/House/Update", formObj, function (data) {
                        if (data.State == 1) {
                            //弹出提示信息
                            layer.msg('修改成功', { icon: 1 });
                            //关闭遮罩层
                            //刷新列表
                            parent.location.reload();
                        }
                        else {
                            layer.msg(data.ErrorMessage, { icon: 5 });
                        }

                    }, "json");
                }

            });


            //区域-小区联动

            $("#RegionId").change(function () {
                //获取当前选择的Id
                var regionId = $(this).val();
                var cid=@Html.DisplayFor(e => e.CommunityId);
                if (regionId) {
                    //发送ajax请求获取小区信息
                    $.post("/House/GetCommunities", { regionId: regionId }, function (data) {

                        //清空现有的校区信息
                        $("#sel_CommunityId").empty();

                        //添加新的option
                        for (var i = 0; i < data.length; i++) {
                            var item = data[i];
                            var option = "<option value=" + item.Id + ">" + item.Name + "</option>";
                            if (item.Id == cid) {
                                option = "<option value=" + item.Id + " selected>" + item.Name + "</option>";
                            }


                            $("#sel_CommunityId").append(option);
                        }
                    }, "json");
                }
            }).trigger("change");

            //$("#RegionId").trigger("change");
        });

    </script>
}
